﻿<%
'自动打开数据库连接
Const DataBaseIp="125.65.77.30"
Const DataBaseName = "test"
Const DataBaseUID = "song"
Const DataBasePwd = "songfeiok"
dim gbdatabaseCheckSec : gbdatabaseCheckSec = "数据库例行检查,操作失败.若想继续浏览请先关闭浏览器重新进入本网站。"
dim objConn
sub OpenDB
	dim strConn
	strConn= "provider=sqloledb;driver={sql server};database="&DataBaseName&";server="&DataBaseIp&";uid="&DataBaseUID&";pwd="&DataBasePwd&";" 
	Set objConn=Server.CreateObject("ADODB.Connection")  '创建数据库连接对象	
	objConn.Open strConn
	If Err Then
		Err.Clear
		Set objConn = Nothing
		Response.Write "<font size=""2"">[数据库连接错误]</font>"
		Response.End
	End If
end sub
'关闭连接
sub CloseDB	
	if(isobject(objConn)) then
   		objConn.close
   		set objConn=nothing   
    end if 
end sub
Sub ResponseClose(str)
	CloseDB
	response.Write str
	response.End()
End Sub


Call OpenDB()
Set rs = objConn.execute("select id, username from test")
While Not rs.eof
    Response.write(rs("id")&rs("username"))
wend


%>